home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-09 | 8.9 KB | 347 lines | [TEXT/MPS ] |
- {*******************************************************************************
- UTest.p
- This file describes the classes used in the Test program itself..
- *******************************************************************************}
-
- UNIT UTest;
-
- INTERFACE
- USES
- { • MacApp }
- UMacApp,
-
- { • Building Blocks }
- UDialog,
- UPrinting,
-
- { • Implementation Use }
- Packages,
- Resources,
- Script,
- UValidText,
- UDateTimeText;
-
- {--------------------------------------------------------------------------}
-
- CONST
- kSignature = 'demo'; { Application signature}
- kFileType = 'dmo1'; { signature of created documents }
-
- kDialogWindowID = 2001; { dialog window's resource ID }
- kDialogViewID = 2002; { dialog view's resource ID }
- kDialogViewSIG = 'DLOG'; { dialog view resource's signature }
- kCancelViewSIG = 'CNCL'; { cancel button's view resource's sig }
-
- cEnterDateTime = 3000; { show date/time dialog }
-
- {--------------------------------------------------------------------------}
-
- TYPE
- TTestApplication = OBJECT (TApplication)
- PROCEDURE TTestApplication.ITestApplication(
- itsMainFileType: OSType);
- { Initializes the application and globals. }
-
- FUNCTION TTestApplication.DoMenuCommand(
- aCmdNumber: CmdNumber)
- : TCommand;
- OVERRIDE;
-
- PROCEDURE TTestApplication.DoSetupMenus;
- OVERRIDE;
-
- PROCEDURE TTestApplication.OpenNew(
- itsCmdNumber: CmdNumber);
- OVERRIDE;
- END; { TTestApplication }
-
- TFixedPopup = OBJECT(TPopup)
- PROCEDURE TFixedPopup.AdjustBotRight;
- OVERRIDE;
- { This override leaves the right-hand edge of the popup alone. }
- END; { TFixedPopup }
-
- TTestDialog = OBJECT(TDialogView)
- PROCEDURE TTestDialog.DoChoice(
- origView: TView;
- itsChoice: INTEGER);
- OVERRIDE;
- { This routine updates either gDefaultDateForm or the 'DATE'
- view's fDateForm field, depending on which of its popup
- menu control subviews was selected. }
- END; { TTestDialog }
-
- {--------------------------------------------------------------------------}
- IMPLEMENTATION
- {--------------------------------------------------------------------------}
-
- PROCEDURE TTestApplication.ITestApplication(
- itsMainFileType: OSType);
- VAR
- dummy: BOOLEAN;
-
- BEGIN
- IApplication(itsMainFileType);
-
- { So the linker doesn't dead strip class info }
- IF gDeadStripSuppression
- THEN
- BEGIN
- dummy := Member(TObject(NIL), TDateEditText);
- dummy := Member(TObject(NIL), TTimeEditText);
- dummy := Member(TObject(NIL), TFixedPopup);
- dummy := Member(TObject(NIL), TTestDialog);
- END;
- END; { ITestApplication }
-
- {--------------------------------------------------------------------------}
-
- FUNCTION TTestApplication.DoMenuCommand(
- aCmdNumber: CmdNumber)
- : TCommand;
- OVERRIDE;
-
- VAR
- theWindow: TWindow;
- theDialog: TDialogView;
- cancelled: BOOLEAN;
- oldTimeCycle: Byte;
- h: Intl0Hndl;
-
- BEGIN
- DoMenuCommand := gNoChanges;
-
- CASE aCmdNumber OF
- cEnterDateTime:
- BEGIN
- { put up the demo dialog }
- theWindow := NewTemplateWindow(kDialogWindowID, NIL);
- FailNil(theWindow);
- theDialog := TDialogView(theWindow.FindSubView(kDialogViewSIG));
- FailNil(theDialog);
-
- { save current time cycle }
- h := Intl0Hndl(IUGetIntl(0));
- FailNil(h);
- oldTimeCycle := h^^.timeCycle;
-
- theDialog.SelectEditText('DATE', TRUE);
- cancelled := (theDialog.PoseModally = kCancelViewSIG);
- theWindow.Close;
-
- { restore the saved time cycle }
- h := Intl0Hndl(IUGetIntl(0));
- FailNil(h);
- h^^.timeCycle := oldTimeCycle;
- END; { cEnterDateTime }
-
- OTHERWISE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END; { case }
- END; { DoMenuCommand }
-
- {--------------------------------------------------------------------------}
-
- PROCEDURE TTestApplication.DoSetupMenus;
- OVERRIDE;
- BEGIN
- INHERITED DoSetupMenus;
-
- Enable(cEnterDateTime, TRUE);
- END; { DoSetupMenus }
-
- {--------------------------------------------------------------------------}
-
- PROCEDURE TTestApplication.OpenNew(
- itsCmdNumber: CmdNumber);
- OVERRIDE;
- { This OVERRIDE is the official way to prevent the opening of a new,
- untitled document whenever the program starts (see UMacApp.p, in
- the defintion of TApplication.OpenNew().) }
- BEGIN
- IF (itsCmdNumber <> cFinderNew)
- THEN
- INHERITED OpenNew(itsCmdNumber);
- END; { OpenNew }
-
- {--------------------------------------------------------------------------}
-
- PROCEDURE TTestDialog.DoChoice(
- origView: TView;
- itsChoice: INTEGER);
- OVERRIDE;
- { This routine handles the interactions between the various dialog
- controls. It's big, it's ugly, it uses a case statement — but
- it works, OK? }
-
- VAR
- curItem: INTEGER;
- theDateForm: INTEGER;
- datePopup: TPopup;
- globalPopup: TPopup;
- dateView: TDateEditText;
- timeView: TTimeEditText;
-
- {----------------------------------------------------------------------}
-
- PROCEDURE ToggleTimeCycle;
- VAR
- h: Intl0Hndl;
-
- BEGIN
- h := Intl0Hndl(IUGetIntl(0));
- FailNil(h);
-
- WITH h^^ DO
- BEGIN
- IF (timeCycle = 0)
- THEN
- timeCycle := 255 { 12-hour cycle }
- ELSE
- timeCycle := 0; { 24-hour cycle }
- END; { with h^^ }
- END; { ToggleTimeCycle }
-
- {----------------------------------------------------------------------}
-
- BEGIN { DoChoice }
- CASE itsChoice OF
- mPopupHit:
- BEGIN
- { get a number of sub-view references }
- datePopup := TPopup(FindSubView('pDAT'));
- FailNil(datePopup);
-
- globalPopup := TPopup(FindSubView('pGLO'));
- FailNil(globalPopup);
-
- dateView := TDateEditText(FindSubView('DATE'));
- FailNil(dateView);
-
- IF (origView = datePopup)
- THEN
- BEGIN
- { change the fDateForm field of the TDateEditText item }
- curItem := datePopup.GetCurrentItem;
-
- CASE curItem OF
- 1..3:
- theDateForm := curItem - 1; { <= [0..2] }
-
- OTHERWISE
- theDateForm := kDefDateForm; { <= 255 }
- END; { case curItem }
-
- dateView.SetDateForm(theDateForm, kRedraw);
- dateView.SetSelection(0, maxint, kRedraw);
- END
- ELSE IF (origView = globalPopup)
- THEN
- BEGIN
- { change the value of the gDefaultDateForm global }
- SetDefaultDateForm(DateForm(globalPopup.GetCurrentItem
- - 1));
-
- { update the dateView, if it depends on gDefaultDateForm }
- IF (dateView.GetDateForm = kDefDateForm)
- THEN
- BEGIN
- dateView.UpdateText(kRedraw);
- dateView.SetSelection(0, maxint, kRedraw);
- END;
- END;
- END; { mPopupHit }
-
- mCheckBoxHit:
- BEGIN
- { get a reference to the 'TIME' time edit text item }
- timeView := TTimeEditText(FindSubView('TIME'));
- FailNil(timeView);
-
- { get a reference to the 'DATE' date edit text item }
- dateView := TDateEditText(FindSubView('DATE'));
- FailNil(dateView);
-
- IF (origView = FindSubView('HOUR'))
- THEN
- BEGIN
- { toggle the time cycle (12-hours or 24-hours) }
- ToggleTimeCycle;
-
- timeView.UpdateText(kRedraw);
- timeView.SetSelection(0, maxint, kRedraw);
- END
- ELSE IF (origView = FindSubView('SECS'))
- THEN
- BEGIN
- { toggle 'want secs' }
- timeView.SetWantSeconds((NOT timeView.GetWantSeconds),
- kRedraw);
- timeView.SetSelection(0, maxint, kRedraw);
- END
- ELSE IF (origView = FindSubView('Vlid'))
- THEN
- BEGIN
- { toggle strict validation }
- timeView.SetStrict(
- TCheckBox(origView).IsOn);
-
- dateView.SetStrict(
- TCheckBox(origView).IsOn);
- END
- ELSE IF (origView = FindSubView('rqur'))
- THEN
- BEGIN
- { toggle fRequire field }
- timeView.SetRequired(
- TCheckBox(origView).IsOn);
-
- dateView.SetRequired(
- TCheckBox(origView).IsOn);
- END;
- END; { mCheckBoxHit }
- END; { case itsChoice }
-
- INHERITED DoChoice(origView, itsChoice);
- END; { DoChoice }
-
- {--------------------------------------------------------------------------}
-
- PROCEDURE TFixedPopup.AdjustBotRight;
- OVERRIDE;
-
- VAR
- numItems: INTEGER;
- newHeight: INTEGER;
- newWidth: INTEGER;
- savedPort: GrafPtr;
- theFontInfo: FontInfo;
-
- BEGIN
- IF fMenuHandle <> NIL THEN
- BEGIN
- CalcMenuSize(fMenuHandle);
- numItems := CountMItems(fMenuHandle);
- (* newWidth := fMenuHandle^^.menuWidth +
- fItemOffset +
- fInset.left +
- fInset.right +
- 3;
- *)
-
- GetPort(savedPort);
- SetPort(gWorkPort);
- SetPortTextStyle(gSystemStyle);
- GetFontInfo(theFontInfo);
- SetPort(savedPort);
-
- WITH theFontInfo DO
- newHeight := ascent + descent + leading + fInset.top + fInset.bottom + 3;
-
- (* Resize(newWidth, newHeight, kDontRedraw); *)
- Resize(fSize.h, newHeight, kDontRedraw);
- END;
- END; { AdjustBotRight }
-
- END. { UTest.p }
-